// 日历
layui.use('laydate', function(){
    var laydate = layui.laydate;
    laydate.render({
        elem: '#leavetime' 
    });
});
// 设置input点击后的边框颜色
$("input").on('focus',function() {
    $(this).css('border','1px solid blue').parent().siblings().children('input').css('border','1px solid #ccc');
});
$(".inp:eq(5) input").on('focus',function() {
    $(this).css('border','1px solid blue').siblings('input').css('border','1px solid #ccc');
});
// 设置x符号显示与隐藏
$("#leavetime").on('change',function() {
    if($(this).val() != ''){
        $(".fa-times-circle-o").css('display','block');
    }else{
        $(".fa-times-circle-o").css('display','none');
    }
});
$("#leavetime").on('click',function() {
    if($(this).val() != ''){
        $(".fa-times-circle-o").css('display','block');
    }else{
        $(".fa-times-circle-o").css('display','none');
    }
});
$(".fa-times-circle-o").on('click',function() {
    $("#leavetime").val('');
    $(this).css('display','none');
});
// 设置活动方式的下拉
var onOff = true;
$("#activity").click(function() {
    $(this).css('border','1px solid blue');
    if(onOff){
        $(".list_hide").slideDown(300);
        $('.one').css({
            transform: 'rotate(-180deg)',
            transition: '0.5s'
        });
        onOff = false;
    }else{
        $(".list_hide").slideUp(300);
        $('.one').css({
            transform: 'rotate(0deg)',
            transition: '0.5s'
        });
        onOff = true;
    }
});
$("#activity").focusout(function() {
    $(".list_hide").slideUp(300);
    $('.one').css({
        transform: 'rotate(0deg)',
        transition: '0.5s'
    });
    onOff = true;
});
$(".list_hide li").on('click',function() {
    $(".list_hide").slideUp(300);
    $("#activity").val($(this).html());
    $('.one').css({
        transform: 'rotate(0deg)',
        transition: '0.5s'
    });
    onOff = true;
});
// 地区省份下拉效果
$("#region").on('click',function() {
    if(onOff){
        $(".reg_list").slideDown(300);
        $('.two').css({
            transform: 'rotate(-180deg)',
            transition: '0.5s'
        });
        onOff = false;
    }else{
        $(".reg_list").slideUp(300);
        $('.two').css({
            transform: 'rotate(0deg)',
            transition: '0.5s'
        });
        onOff = true;
    }
});
$("#region").on('focusout',function() {
    $(".reg_list").slideUp(300);
        $('.two').css({
            transform: 'rotate(0deg)',
            transition: '0.5s'
        });
        onOff = true;
});
$(".reg_list li").on('click',function() {
    $(".reg_list").slideUp(300);
    $("#region").val($(this).html());
    $('.two').css({
        transform: 'rotate(0deg)',
        transition: '0.5s'
    });
    onOff = true;
});
// 二级联动
var json = [['郑州','周口','开封','洛阳'],['阜阳','合肥','还有哪'],['哪','不知道','算了']]
$(".reg_list li").click(function() {
    var numval = $(this).val();
    $(".shi_list").empty();
    $(".reg_list li").each(function(i,v){
        $(".shi_list").append('<li>'+ json[numval][i] +'</li>');
        $(".shi_list").css('border','1px solid #ccc');
        $(".shi_list li").on('click',function() {
            $(".shi_list").slideUp(300);
            $("#shi").val($(this).html());
            $('.three').css({
                transform: 'rotate(0deg)',
                transition: '0.5s'
            });
            onOff = true;
        });
});
});
// 地区市份下拉效果
$("#shi").on('click',function() {
    if(onOff){
        $(".shi_list").slideDown(300);
        $('.three').css({
            transform: 'rotate(-180deg)',
            transition: '0.5s'
        });
        onOff = false;
    }else{
        $(".shi_list").slideUp(300);
        $('.three').css({
            transform: 'rotate(0deg)',
            transition: '0.5s'
        });
        onOff = true;
    }
});
$("#shi").on('focusout',function() {
    $(".shi_list").slideUp(300);
        $('.three').css({
            transform: 'rotate(0deg)',
            transition: '0.5s'
        });
        onOff = true;
});
// 修改信息按钮
$("#change_msg").click(function() {
    $("#ifram_c")[0].contentWindow.close_c();
});
// 格式化日期，如月、日、时、分、秒保证为2位数
function formatNumber (n) {
    n = n.toString()
    return n[1] ? n : '0' + n;
}
// 参数number为毫秒时间戳，format为需要转换成的日期格式
function formatTime (number, format) {
    let time = new Date(number)
    let newArr = []
    let formatArr = ['Y', 'M', 'D', 'h', 'm', 's']
    newArr.push(time.getFullYear())
    newArr.push(formatNumber(time.getMonth() + 1))
    newArr.push(formatNumber(time.getDate()))

    newArr.push(formatNumber(time.getHours()))
    newArr.push(formatNumber(time.getMinutes()))
    newArr.push(formatNumber(time.getSeconds()))

    for (let i in newArr) {
        format = format.replace(formatArr[i], newArr[i])
    }
    return format;
}
// 提醒栏
var onOff = true;
var ulTop;
var iTimer;
$('.rightMsg').click(function () {
    if (onOff) {
        // 提醒信息接口
        $.ajax({
            url:academyURL+':9999/oaSystem/school',
            type:'get',
            data:{
                "method": "remindschool",
                "empId": "10001"
            },
            dataType:'json',
            success:function(data) {
                $(".listMsg ul").empty();
                console.log(data);
                for(var i=0; i<data.result.length; i++){
                    if(data.result[i].remindTypeId == "1"){
                        $(".listMsg ul").append('<li><span>待跟进量提醒</span><span>'+ data.result[i].remindContent +'</span><span>'+ formatTime(data.result[i].remindTime,"Y-M-D") +'</span></li>');
                    }else if(data.result[i].remindTypeId == "2"){
                        $(".listMsg ul").append('<li><span>转公共量提醒</span><span>'+ data.result[i].remindContent +'</span><span>'+ formatTime(data.result[i].remindTime,"Y-M-D") +'</span></li>');
                    }else if(data.result[i].remindTypeId == "3"){
                        $(".listMsg ul").append('<li><span>接受量提醒</span><span>'+ data.result[i].remindContent +'</span><span>'+ formatTime(data.result[i].remindTime,"Y-M-D") +'</span></li>');
                    }
                }
                $(".listMsg ul li span:eq(0)").css("width",'100px');
            },
            error:function(xhr,error){
                console.error(error);
            }

        });
        // 改变小图标
        $('.rightMsg em').addClass('fa fa-wheelchair-alt');
        $('#promessage').animate({
            height: 250
        }, 400, function () {
            console.log('111');
            $('.listMsg').css('display', 'block');
            // 添加定时器
            iTimer = setInterval(function () {
            if (($('.listMsg').scrollTop() + $('.listMsg').height()) >= $('.listMsg ul').height()) {
                // 滚动到底部时回到顶部继续滚动
                ulTop = 0;
                $('.listMsg').scrollTop(ulTop + 1);
            }else{
                ulTop = $('.listMsg').scrollTop();
                $('.listMsg').scrollTop(ulTop + 1);
            }
            }, 60);
        });
        onOff = false;
    } else {
        $('.rightMsg em').removeClass('fa fa-wheelchair-alt');
        clearInterval(iTimer)
        $('.rightMsg em').addClass('fa fa-wheelchair');
        $('#promessage').animate({
            height: 50
        }, 400, function () {
            $('.listMsg').css('display', 'none');
        });
        onOff = true;
    }
});

